#include "processbar.h"

//void ForTest()
//{
//  printf("test test\n");
//}

#define Length 101
#define Style '*'
const char* lable="\\|-/";

//version1
//void ProcBar()
//{
//  char bar[Length];
//  memset(bar,'\0',sizeof(bar));
//  int len=strlen(lable);
//  int count=0;
//  while(count<=100)
//  {
//    printf("[%-100s][%d%%][%c]\r",bar,count,lable[count%len]);
//    fflush(stdout);
//    bar[count++]=Style;
//    usleep(50000);
//  }
//  printf("\n");
//}

//version2
void ProcBar(double filesize,double current)
{

  char bar[Length];
  memset(bar,'\0',sizeof(bar));
  int len=strlen(lable);
  int count=0;
  int loop_count=(int)(current*100/filesize);//循环次数
  while(count<=loop_count)
  {
    bar[count++]=Style;
  }
    printf("[%-100s][%3d][%c]\r",bar,loop_count,lable[count%len]);
    fflush(stdout);
}
